package role

import (
	"context"

	"github.com/gogf/gf/v2/errors/gerror"

	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/role/v1"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/consts"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"
)

func (c *ControllerV1) UnassignUser(ctx context.Context, req *v1.UnassignUserReq) (res *v1.UnassignUserRes, err error) {
	tenantCode := ctx.Value(consts.TokenClaims.TenantCode).(string)

	if len(req.UsersId) == 0 {
		return nil, gerror.NewCode(consts.MustSelectAtLeastOneUser)
	}
	in := &v1.UnassignUserInput{
		TenantCode: tenantCode,
		Id:         req.Id,
		UsersId:    req.UsersId,
	}
	out := &v1.UnassignUserOutput{}
	out, err = service.Role().UnassignUser(ctx, in)
	if err != nil {
		return nil, err
	}
	return &v1.UnassignUserRes{Rows: out.Rows}, nil
}
